package top.jiangqiang.qyblog.common.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jiangqiang
 * @date 2022-07-24
 */
@Configuration
@ConfigurationProperties(prefix = "global")
@Data
public class GlobalProperties {
    private ProjectInfo info;
    private SecurityConfig security;
    private FileConfig fileConfig;
    /**
     * 系统启动时自动初始化用户
     * 如果用户名和密码同时一样，并且配置多个，会自动去重，但是如果出现一个用户名对应多个密码，就会报错，程序终止
     */
    private List<UserConfig> users = new ArrayList<>();

    @Data
    public final static class SecurityConfig {
        //加密使用的key
        private String password = "54597237ca1f9e8b793c3b65d0589506";
        /**
         * 允许匿名访问的路径
         */
        private List<String> allowAnonymousAccess = new ArrayList<>();
    }

    @Data
    public final static class ProjectInfo {
        private String version;
        private String name;
    }

    @Data
    public final static class FileConfig {
        //静态资源路径映射
        private Map<String, String> staticResourceMapping = new HashMap<>();
        //文件上传路径
        private String uploadPath;
        //缓存路径
        private String cachePath;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public final static class UserConfig {
        private String username;
        private String password;
    }
}
